package com.lesshassles.model;

import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class UserBrokerImpl extends HibernateDaoSupport implements UserBroker {

	public List<User> getUsers() {
		return (List<User>)getSession()
			.createQuery("from User")
			.list();
	}
	
	public User getUserByLogin(String email, String password) {
	    return (User)getSession()
	    	.createQuery("from User where email = :email and password = SHA1(:password)")
		    .setString("email", email)
		    .setString("password", password)
		    .uniqueResult();
	}
	
	public User getById(int userId) {
		return (User)getSession()
			.createQuery("from User where id = :id")
			.setInteger("id", userId)
			.uniqueResult();
	}
	
}
